package com.stooscloud.provider.service.impl;

import com.stooscloud.base.exception.BusinessException;
import com.stooscloud.provider.RequestHanlder;
import com.stooscloud.provider.service.DSPService;
import com.stooscloud.wrapper.WrapMapper;
import com.stooscloud.wrapper.Wrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Service
@Slf4j
public class DSPServiceImpl implements DSPService {
    @Resource
    RequestHanlder requestHanlder;
    @Override
    public Wrapper handler(HttpServletRequest request) {
        String errCode;
        String errMsg;
        try {
            return requestHanlder.handler(request);
        }catch (Exception e){
            if (e instanceof BusinessException){
                errCode = ((BusinessException) e).getCode()+ "";
                errMsg = e.getMessage();
            }else {
                errCode = "1005";
                errMsg = e.getMessage();
            }
        }
        return WrapMapper.wrap(errCode,errMsg);
    }



}
